package com.example.testproject.activity

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.testproject.R

/**
 *
 * @ClassName: InstanceStateActivity
 * @Author: android 超级兵
 * @CreateDate: 4/6/22$ 9:50 AM$
 * TODO
 */
class InstanceStateActivity :AppCompatActivity() {

    private val tvState by lazy{findViewById<TextView>(R.id.tvState)}

    companion object{
        const val STAGE_KEY_STRING = "state_key_string"
        const val STAGE_KEY_INT  = "state_key_int"
        const val STAGE_KEY_FLOAT  = "state_key_float"
        const val STAGE_KEY_BOOL  = "state_key_bool"
        const val STAGE_KEY_ARRAY_INT  = "stage_key_array_int"
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_instance_state)
        savedInstanceState?.apply {
            tvState.text = String.format("%s\n%s\n%s\n%s\n%s",
                getString(STAGE_KEY_STRING),
                getInt(STAGE_KEY_INT).toString(),
                getFloat(STAGE_KEY_FLOAT).toString(),
                getBoolean(STAGE_KEY_BOOL).toString(),
                getIntArray(STAGE_KEY_ARRAY_INT).toString()
                )
        }
        Log.i(this.javaClass.simpleName,"onCreate")
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        Log.i(this.javaClass.simpleName,"onSaveInstanceState")
        outState.putString(STAGE_KEY_STRING,"test str")
        outState.putInt(STAGE_KEY_INT,123)
        outState.putFloat(STAGE_KEY_FLOAT,3.1415926f)
        outState.putBoolean(STAGE_KEY_BOOL,true)
        outState.putIntArray(STAGE_KEY_ARRAY_INT, intArrayOf(2,3,4,5,6,7,8,1))
    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        Log.i(this.javaClass.simpleName,"onNewIntent")
    }
    override fun onStart() {
        super.onStart()
        Log.i(this.javaClass.simpleName,"onStart")
    }

    override fun onResume() {
        super.onResume()
        Log.i(this.javaClass.simpleName,"onResume")
    }

    override fun onRestart() {
        super.onRestart()
        Log.i(this.javaClass.simpleName,"onRestart")
    }

    override fun onPause() {
        super.onPause()
        Log.i(this.javaClass.simpleName,"onPause")
    }

    override fun onStop() {
        super.onStop()
        Log.i(this.javaClass.simpleName,"onStop")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.i(this.javaClass.simpleName,"onDestroy")
    }
}

